const eventBus = require('../../utils/eventbus.js');
const myRequest=require("../../utils/myRequest.js")
Page({
  data: {
    car:[],
    place: wx.getStorageSync('currentPlace') || null
  },

  onLoad: function (options) {
   let car=JSON.parse(options.car)
    this.setData({
      car:car
    })
    eventBus.on('choicePlace', (place) => {
      console.log('preview ', place);
      this.setData({
        place: place
      })
    })
  },
  place(){
    wx.navigateTo({
      url: '../place/place',
    })
  },
  payment(){
    wx.showLoading({
      title: '支付中',
      mask:true
    })
    myRequest.request({
      url: 'http://localhost:3000/api/payment',
      data: {
        goodsitems:this.data.car,
        place:this.data.place
      },
      method: 'POST',
      dataType: 'json',
      success: function(res) {
        console.log(res)
        if(res.data.status===10000){
          wx.hideLoading();
          eventBus.emit('refreshAmount')
          wx.navigateTo({
            url: '../success/success',
          })
        }
      }
    })
  }
})